package com.shujia.map_;

import org.junit.Test;

import java.util.*;

public class MapDemo2 {

    @Test
    public void test2() {
        // LinkedHashMap 通过双向链表记住entry的添加顺序
        // Hashtable不能存放null的key
        // HashMap key可以为null, null就是一个特殊的key
//        Map<Integer, String> map = new Hashtable<>();
        Map<Integer, String> map = new HashMap<>();
        map.put(null, "李四");
        map.put(null, "李四aa");
        map.put(1003, "王五");
        map.put(1001, "张三");

        Set<Map.Entry<Integer, String>> entrySet = map.entrySet();

        for (Map.Entry<Integer, String> entry : entrySet) {
            System.out.println("key:" + entry.getKey());
            System.out.println("value:" + entry.getValue());
        }
    }

    @Test
    public void test1() {
        // LinkedHashMap 通过双向链表记住entry的添加顺序
        Map<Integer, String> map = new LinkedHashMap<>();
        map.put(1002, "李四");
        map.put(1003, "王五");
        map.put(1001, "张三");

        Set<Map.Entry<Integer, String>> entrySet = map.entrySet();

        for (Map.Entry<Integer, String> entry : entrySet) {
            System.out.println("key:" + entry.getKey());
            System.out.println("value:" + entry.getValue());
        }
    }
}
